import { ADD_COUNTER, ADD_CART } from './mutations-type'
export default {
    addCart(context, payload) {
        return new Promise(reslove => {
            //查找之前数组是否已经包含该商品
            let oldProduct = context.state.cartList.find(item => item.iid === payload.iid)

            console.log(oldProduct)

            //判断
            if (oldProduct) { //已存在  数量+1
                context.commit(ADD_COUNTER, oldProduct)
                reslove('商品数量+1')
            } else { //不存在
                payload.count = 1
                context.commit(ADD_CART, payload)
                reslove('加入新商品')
            }
        })

    }
}